/*****************************************************************************
 * plum_shell.h
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/
#ifndef __PLUM_SHELL_H__
#define __PLUM_SHELL_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/** shell section name */
#define PLUM_SHELL_SECTION plum_shell

/*****************************************************************************
 * Public Types
 ****************************************************************************/

typedef struct {
    /** Command command strings. */
    PLUM_CONST plum_s8 *cmd;

    /** Command describe string. */
    PLUM_CONST plum_s8 *desc;

    /** Command handler. */
    plum_void (*handler)(plum_u32 argc, plum_s8 *argv[]);
} PLUM_SECTION_ALIGNMENT plum_shell_t;

/*****************************************************************************
 * Public Data
 ****************************************************************************/
/* use section table record plum_shell_t */
PLUM_SECTION_DEF(PLUM_SHELL_SECTION, plum_shell_t);

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief   注册shell命令
 *
 * @param[in]  shell_cmd    -   shell命令
 * @param[in]  cmd_desc     -   命令描述
 * @param[in]  cmd_handle   -   命令回调
 *
 * @note    所有命令不能重名
 **/
#define PLUM_SHELL_EXPORT(shell_cmd, cmd_desc, cmd_handle)                 \
    PLUM_SECTION_ITEM_REGISTER(PLUM_SHELL_SECTION,                         \
                               plum_shell_t shell_##cmd_handle) = {        \
        (PLUM_CONST plum_s8 *)(shell_cmd), (PLUM_CONST plum_s8 *)cmd_desc, \
        cmd_handle}

/**
 * @brief   shell初始化
 *
 * @param[in]  get_char    -   shell获取命令回调
 *
 * @return  返回执行状态
 **/
plum_s32 plum_shell_init(plum_s32 (*get_char)(plum_void));

/**
 * @brief   shell释放
 *
 * @return  返回执行状态
 **/
plum_s32 plum_shell_deinit(plum_void);

/**
 * @brief   挂起shell组件
 *
 * @return  返回执行状态
 **/
plum_s32 plum_shell_suspend(plum_void);

/**
 * @brief   恢复shell组件
 *
 * @return  返回执行状态
 **/
plum_s32 plum_shell_resume(plum_void);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __PLUM_SHELL_H__ */
/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
